// 配置全局的请求根路径
axios.defaults.baseURL = 'http://api-breakingnews-web.itheima.net'

// 添加请求拦截器
axios.interceptors.request.use(config => {
    // 发送请求前带上token
    if (config.url.indexOf('/my') !== -1) {
        config.headers.Authorization = localStorage.getItem('token')
    }
    return config;
}, error => {
    // Do something with request error
    return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(response => {
    // Do something before response is sent
    console.log(response)
    if (response.data.status === 1 && response.data.message === '身份认证失败！') {
        localStorage.removeItem('token')
        location.href = '/login.html'
    }
    return response;
}, error => {
    // Do something with response error
    return Promise.reject(error);
});
